package cn.virens.common.mybatis.entity;

import io.mybatis.provider.Entity;

@SuppressWarnings("serial")
public class BaseModelLock extends BaseModel {
    public static final Integer DEF_LOCK = 0;

    @Entity.Column(value = "lock_flag", remark = "乐观锁")
    private Integer lockFlag;

    public Integer getLockFlag() {
        return lockFlag;
    }

    public void setLockFlag(Integer lockFlag) {
        this.lockFlag = lockFlag;
    }

    @SuppressWarnings("unchecked")
    public <T extends BaseModelLock> T incrementAndGet(Integer inc) {
        this.lockFlag = lockFlag + inc;

        return (T) this;
    }

    @SuppressWarnings("unchecked")
    public <T extends BaseModelLock> T incrementAndGet(T lock, Integer inc) {
        this.lockFlag = lock.getLockFlag() + inc;

        return (T) this;
    }
}
